package com.yuanyu.server.impl;

import com.yuanyu.common.util.AssertUtil;
import com.yuanyu.common.util.CopyUtil;
import com.yuanyu.mapper.mysqlMapper.Hoisting_pump.Hoisting_pump_1_Mapper;
import com.yuanyu.mapper.mysqlMapper.Hoisting_pump.Hoisting_pump_Mapper;
import com.yuanyu.mapper.mysqlMapper.MainTable_Mapper;
import com.yuanyu.model.dto.Hoisting_pumpDTO;
import com.yuanyu.model.entity.Hoisting_pump.Hoisting_pump;
import com.yuanyu.model.entity.Hoisting_pump.Hoisting_pump_1;
import com.yuanyu.model.vo.Hoisting_pumpVO;
import com.yuanyu.server.ITestPart7Server;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;

@Service
@Transactional
public class TestPart7ServerImpl implements ITestPart7Server {
    @Autowired
    private Hoisting_pump_Mapper hoistingPumpMapper;
    @Autowired
    private Hoisting_pump_1_Mapper hoistingPump1Mapper;
    @Autowired
    private MainTable_Mapper mainTableMapper;


    @Override
    public String test() {
        return "测试成功";
    }

    @Override
    public String test7(Hoisting_pumpVO hoistingPumpVO) {
        Hoisting_pump test = hoistingPumpMapper.selTableTime(hoistingPumpVO.getInput_Case());
        AssertUtil.isNull(test,"Case已存在,如需修改内容请前往后台修改");

        Hoisting_pump hoistingPump = new Hoisting_pump();
        Hoisting_pump_1 hoistingPump1 = new Hoisting_pump_1();

        CopyUtil.copyClass(hoistingPumpVO,hoistingPump);
        hoistingPump.setCreatedAt(LocalDateTime.now());
        hoistingPump.setUpdatedAt(LocalDateTime.now());
        CopyUtil.copyClass(hoistingPumpVO,hoistingPump1);

        System.out.println(hoistingPump);
        System.out.println(hoistingPump1);

        int i = hoistingPumpMapper.addTableTime(hoistingPump);
        int i1 = hoistingPump1Mapper.addTable1(hoistingPump1);

        AssertUtil.isTrue(i == 1 && i1 == 1,"添加数据出现异常,请检查");
        mainTableMapper.updateByCaseFormStartTime(hoistingPumpVO.getInput_Case());
        return "添加成功";
    }

    @Override
    public String updateTable7(Hoisting_pumpVO hoistingPumpVO) {
        Hoisting_pump hoistingPump = new Hoisting_pump();
        Hoisting_pump_1 hoistingPump1 = new Hoisting_pump_1();

        CopyUtil.copyClass(hoistingPumpVO,hoistingPump);
        hoistingPump.setUpdatedAt(LocalDateTime.now());
        CopyUtil.copyClass(hoistingPumpVO,hoistingPump1);

        int i = hoistingPumpMapper.updateTableTime(hoistingPump);
        int i1 = hoistingPump1Mapper.updateTable1(hoistingPump1);

        AssertUtil.isTrue(i == 1 && i1 == 1,"表7修改数据出现异常,请检查");
        return "修改成功";
    }

    @Override
    public Hoisting_pumpDTO getTest7(String Case) {
        Hoisting_pump hoistingPump = hoistingPumpMapper.selTableTime(Case);
        if (hoistingPump == null)return null;
        Hoisting_pump_1 hoistingPump1 = hoistingPump1Mapper.selTable1(Case);

        Hoisting_pumpDTO hoistingPumpDTO = new Hoisting_pumpDTO();
        CopyUtil.copyClass(hoistingPump,hoistingPumpDTO);
        CopyUtil.copyClass(hoistingPump1,hoistingPumpDTO);
        return hoistingPumpDTO;
    }
}
